package com.sixth.service.impl;

import com.sixth.dao.EduCourseDao;


import com.sixth.entity.EduCourse;
import com.sixth.service.CouseService;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 厉泽禄
 * @create: 2022-04-19 20:48
 **/
@Service(value = "courseService")
public class CouseServiceImpl implements CouseService {
    @Autowired
    private EduCourseDao courseDao;
    @Override
    public CommonResult queryAllCourseRanking(EduCourse course) {
        String startTime=null;
        String stopTime=null;
        if(course.getGmt_create()!=null&&course.getGmt_modified()!=null){
            String s1= course.getGmt_create()+"";
            String s2= course.getGmt_modified()+"";
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date format1 = new Date(s1);
                Date format2 = new Date(s2);
                String start = format.format(format1);
                String stop = format.format(format2);
                startTime = format.parse(start).toLocaleString();
                stopTime = format.parse(stop).toLocaleString();
                List<EduCourse> courses = courseDao.queryAllCourseRanking(startTime, stopTime);
                return new CommonResult(2000,"查询成功",courses);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        List<EduCourse> courses = courseDao.queryAllCourseRanking(startTime, stopTime);
        return new CommonResult(2000,"查询成功",courses);
    }
}

